<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>

    <title>正在跳转</title>
<!--    <script src="js/alert.js"></script>-->
</head>
<body style="text-align: center">
正在跳转
</body>

<script src="js/jquery.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script>
    (function ($) {
        $.getUrlParam1 = function (name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null)
                return decodeURI(r[2]);
            return null;
        }
    })(jQuery);
</script>
<script>
    var appid;
    var redirect_url;
    var response_type;
    var scope;
    var state;
    var url;
    $(document).ready(function () {
            var code = $.getUrlParam1("code");
            if (code != null) {
                getcode(code);

                return
            }

            var token = $.getUrlParam1("token");
            var phone = $.getUrlParam1("phone");
            var openid = $.getUrlParam1("openid");

            setPhone(phone,openid);
            $.ajax({
                "url": "/wechat/rus/",
                "data": "token=" + token,
                "type": "GET",
                "dataType": "json",
                "success": function (json) {
                    var domain = window.location.host;
                    appid = json.data.appid;
                    response_type = json.data.responseType;
                    scope = json.data.scope;
                    state = $.getUrlParam1("token");
                    redirect_url = "https://" + domain + "/wxapp/app-skip.html";

                    url = "https://open.weixin.qq.com/connect/oauth2/authorize?" +
                        "appid=" + appid +
                        "&redirect_uri=" + encodeURIComponent(redirect_url) +
                        "&response_type=" + response_type +
                        "&scope=" + scope +
                        "&state=" + state +
                        "#wechat_redirect";
                    location.href = url;
                }
            })

        }
    );

    function setPhone(phone,openid) {

        $.ajax({
            "url": "/shop/vip/setphone/",
            "data": "phone=" + phone+"&openid="+openid,
            "type": "POST",
            "dataType": "json",
            "success": function (json) {

            }
        })

    }

    function getcode(code) {
        var url = window.location.href;
        $.ajax({
            "url": "/wechat/judge/",
            "data": "code=" + code + "&uri=" + url,
            "type": "POST",
            "dataType": "json",
            "success": function (json) {

                if (json.state == 200) {
                   // location.href = "user.html";
                    wx.miniProgram.navigateTo({url: '/pages/start/start?token=321'})
                } else {
                    location.href = "app-attestation.html";
                }

            }
        })
    }


</script>
</html>